package com.gbx.ximalayating.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gbx.ximalayating.R;
import com.gbx.ximalayating.entity.ListItemBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by kun on 2016/12/6.
 * 榜单适配器
 */

public class MonthlyFocusAdapter extends BaseAdapter {
    private List<ListItemBean> listItemBeens;
    private Context context;
    private LayoutInflater inflater;

    public MonthlyFocusAdapter(List<ListItemBean> listItemBeens, Context context) {
        this.listItemBeens = listItemBeens;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listItemBeens.size();
    }

    @Override
    public Object getItem(int position) {
        return listItemBeens.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView=inflater.inflate(R.layout.monthlyfocus_item_main,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        ListItemBean itemBean = listItemBeens.get(position);
        String imagePath = itemBean.getCoverPath();
        //加载图片
        Picasso.with(context)
                .load(imagePath)
                .into(holder.item_image);
        //大标题
        String title = itemBean.getTitle();
        holder.text1.setText(title);
        //2个小标题
        String title1 = itemBean.getFirstKResults().get(0).getTitle();
        holder.text2.setText("1 "+title1);
        String title2 = itemBean.getFirstKResults().get(1).getTitle();
        holder.text3.setText("2 "+title2);
        return convertView;
    }


    private static class ViewHolder{
        ImageView item_image;
        TextView text1,text2,text3;

        public ViewHolder(View view) {
            item_image = (ImageView) view.findViewById(R.id.mf_list_item_image);
            text1 = (TextView) view.findViewById(R.id.title1);
            text2 = (TextView) view.findViewById(R.id.title2);
            text3 = (TextView) view.findViewById(R.id.title3);
        }
    }
}
